/**
 * @author JackGao
 *			email:jackgao.china@gmail.com
 *  date：2016-6-23
 * 
 */
package cn.cuit.ds.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import cn.cuit.ds.dao.IShopperinfoDao;
import cn.cuit.ds.domain.Shopper;
import cn.cuit.ds.domain.User;
import cn.cuit.ds.utils.JdbcUtils;

@Repository(value="ShopperinfoDao")
public class ShopperinfoDao implements IShopperinfoDao {

	public void add(Shopper Shopper) {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql = "insert into shopperinfo values(?,?,?,?,?)";
		try {
			runner.update(sql,Shopper.getShoperId(),Shopper.getDetail1(),Shopper.getShopName(),Shopper.getRegistTime(),Shopper.getPwd());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public List<Shopper> getAll() {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql = "select * from shopperinfo";
		try {
		     return runner.query(sql,new BeanListHandler<Shopper>(Shopper.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}



	public Shopper findByNameAndPwd(String ShopperName, String pwd) {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql ="select * from shopperinfo where shopName = ? AND pwd=?";
		try {
			return runner.query(sql,new BeanHandler<Shopper>(Shopper.class),ShopperName,pwd);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}



	public Shopper findByName(String ShopperName) {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql ="select * from shopperinfo where shopName=?";
		try {
			return runner.query(sql, new BeanHandler<Shopper>(Shopper.class),ShopperName);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void update(Shopper shopper) {
		// TODO Auto-generated method stub
		
	}

}
